import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/16
 * Time:17:23
 **/
public class Main2 {
    /**
     * 每日一题-连续最大和
     * dp[i] :以i结尾的子数组的连续最大和
     * @param args
     */
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = scanner.nextInt();
            }
            int[] dp = new int[n];
            dp[0] = Math.max(array[0], 0);
            int max = 0;
            for (int i = 1; i < n; i++) {
                dp[i] = Math.max(dp[i - 1] + array[i], 0);
                if (max < dp[i]) {
                    max = dp[i];
                }
            }
            if (max == 0) {
                int max2 = array[0];
                for (int i = 0; i < n; i++) {
                    if (max2 < array[i]) {
                        max2 = array[i];
                    }
                }
                System.out.println(max2);
            } else {
                System.out.println(max);
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] arr = new int[size];

        for (int i = 0; i < size; i++) {
            arr[i] = sc.nextInt();
        }

        int sum = arr[0];
        int max = arr[0];

        for (int i = 1; i < size; i++) {
            sum = Math.max(sum + arr[i],arr[i]);
            if (sum >= max){
                max = sum;
            }
        }
        System.out.println(max);
    }
}
